#include<iostream>

using namespace std;

int n, m;
bool vis[105][105];
char maze[105][105];
int arr[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

bool in(int tx, int ty) {
	return tx >= 0 && tx < n && ty >= 0 && ty < m;
}

bool dfs(int x, int y) {
	if(maze[x][y] == 'T'){
		return true; 
	}
	vis[x][y] = 1;
	maze[x][y] = '!';
	
	for(int i = 0; i < 4; i++) {
		int tx = arr[i][0] + x;
		int ty = arr[i][1] + y;
		if(in(tx, ty) && maze[tx][ty] != '#' && !vis[tx][ty] ) {
			if(dfs(tx, ty)) {
				return true;
			}
		}
	}
	vis[x][y] = 0;
	maze[x][y] = '.';
	return false;
}

int main(void) {
	
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> maze[i];
	}
	int ant = 0;
	int x, y;
	for( int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if(maze[i][j] == 'S') {
				x = i;
				y = j;
				break;	
			}
		}
	}
	
	if(dfs(x, y)) {
		for(int i = 0; i < n; i++) {
			cout << maze[i] << endl;
		}
	} else {
		cout << "wrong path!" << endl;
	}	
	return 0;
}
